home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 …SCII & the Runetime Code / ADC Developer CD (1992-07) (''Butch ASCII And The Runtime Code'')_iso / Dev.CD 199207.iso / Tools & Apps / OS⁄Toolbox / Apple Events / AE Word Services 1.0d6 / Writeswell Jr. Source / MyFiles.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-23  |  2.1 KB  |  99 lines  |  [TEXT/KAHL]

  1. /* MyFiles.c
  2.  * Handle file calls in IAC speller testbed app
  3.  * ©1992 Working Software, Inc.
  4.  * This source code is copyrighted.  Permission is granted to use the Word Services
  5.  * portion of the Writeswell Jr. source code in your own programs, but you 
  6.  * may not distribute the Writeswell Jr. word-processor code as a 
  7.  * commercial product.  If you modify the code, please do not call it 
  8.  * Writeswell Jr. (or Writeswell.)  This will ensure that people understand the 
  9.  * program and don’t have to deal with a number of different versions with 
  10.  * who-knows-what going on in the code.
  11.  * 
  12.  * Writeswell Jr. and Writeswell are trademarks of Working Software, Inc.
  13.  * 6 Sep 91 Mike Crawford
  14.  */
  15.  
  16. #include <Files.h>
  17. #include "MyFiles.h"
  18. #include "AppleEvents.h"
  19. #include "TBConstants.h"
  20. #include "TBGlobals.h"
  21. #include "TestBed.h"
  22. #include "Scroll.h"
  23. #include "Gripe.h"
  24.  
  25. OSErr MyOpenFile( FSSpec *specPtr )
  26. {
  27.     OSErr err;
  28.     Rect txRect;
  29.     char textBuf[ 512 ];
  30.     long bytesRead;
  31.     TEHandle textH;
  32.     
  33.     if ( err = FSpOpenDF( specPtr, fsRdWrPerm, &gRefNum ) ){
  34.         Gripe( "\pFSpOpenDF failed" );
  35.         return err;
  36.     }
  37.     
  38.     if ( MakeNewWindow() ){
  39.         Gripe( "\pMakeNewWindow failed" );
  40.         return err;
  41.     }
  42.     
  43.     SetWTitle( gDocWindow, specPtr->name );
  44.  
  45.     textH = (TEHandle)GetWRefCon( gDocWindow );
  46.  
  47.     do {
  48.         bytesRead = 512;
  49.  
  50.         err = FSRead( gRefNum, &bytesRead, textBuf );
  51.         
  52.         if ( !err || err == eofErr ){
  53.             TEInsert( textBuf, bytesRead, textH );
  54.         }
  55.     } while ( !err );
  56.  
  57.     TESetSelect( 0L, 0L, textH );
  58.  
  59.     return noErr;
  60. }
  61.  
  62. OSErr MakeNewWindow( void )
  63. {
  64.     OSErr err;
  65.     Rect txRect;
  66.     TEHandle textH;
  67.  
  68.     gDocWindow = GetNewWindow( kDocWindowID, (Ptr)NULL, (WindowPtr) -1 );
  69.     if ( !gDocWindow ){
  70.         Gripe( "\pGetNewWindow failed" );
  71.         return err;
  72.     }
  73.     
  74.     SetPort( gDocWindow );
  75.     
  76.     GetTERect( &( thePort->portRect ), &txRect );
  77.     
  78.     textH = TENew( &txRect, &txRect );
  79.     
  80.     if ( !textH ){
  81.         Gripe( "\pTENew failed" );
  82.         return memFullErr;
  83.     }
  84.     
  85.     SetWRefCon( gDocWindow, (long)textH );
  86.     
  87.     gVertScroll = GetNewControl( kVertScrollBarID, gDocWindow );
  88.     if ( !gVertScroll )
  89.         return memFullErr;
  90.  
  91.     ( *textH )->clikLoop = (ProcPtr)TrackContentClick;
  92.  
  93.     SizeVertScroll();
  94.  
  95.     SetVertScroll( gDocWindow, gVertScroll );
  96.  
  97.     return noErr;
  98.     
  99. }